(function(app) {
    app
        .controller("content_10_inputCtrl", ["$scope", "$state", "myFactory", '$stateParams', "$q", '$timeout', '$location', '$http', '$ionicHistory', function($scope, $state, myFactory, $stateParams, $q, $timeout, $location, $http, $ionicHistory) {

            //接收参数
            var itemId = $stateParams.changeTypeId; //变更项目ID
            var chdrnum01 = $stateParams.chdrnum01; //保单号
            var chdrcoy = $stateParams.chdrcoy; //保单公司号码
            //判断是否是同一个人 add by csf 20181219 start
            var isSamePerson = true;
            //判断是否是同一个人 add by csf 20181219 end
            var tj = true;
            var prompt = "";
            var sexLF = 'M';
            var sexOW = 'M';
            var item = "";
            var item10 = "";
            var initFlag = false; //检测标志，在初始化函数完成后，会被置为true
            var isOneYearCrtFlag = true; //是否为非一年期险种
            var isCrsInsureFlag = false;
            var taxBenefitRole = ""; //受益人角色
            var taxClientNo = ""; //投保人/受益人客户号
            var policy; //基础信息
            var token = sessionStorage.getItem("token");
            $scope.chdrnum01 = $stateParams.chdrnum01; //保单号
            $scope.certificateVal = null;
            $scope.show10BbrFlag = true; //默认显示被保人界面
            $scope.show10TbrFlag = false; //默认不显示投保人界面
            $scope.readFlag = false; //阅读协议标志，默认为false
            var orignInsuredInfo = "";
            var nativePlaceOWBefore = "";
            var nativePlaceLFBefore = "";

            $scope.isPhotoOCRFlag = true;

            $scope.data = {
                checkFlag: false,
                radioFlagLF: true,
                radioFlagOW: true,
                certificateChoseId: null,
                certificateList: [],
            };

            //myFactory.getDate('birthDayLF','请选择出生年月日');
            //myFactory.getDate2('birthDayLF','选择出生年月日','2016-12-22');
            //var timeTemp="2017-01-01";
            //myFactory.getDate2('birthDayLF','选择出生年月日',timeTemp);
            //myFactory.getDate('birthDayOW','请选择出生年月日');
            //myFactory.getDate('availDataCloseLF','请选择有效期截止日');
            //myFactory.getDate('availDataCloseOW','请选择有效期截止日');

            /**********************************************初始化函数begin****************************************************/
            //初始化查询变更项内容
            $scope.load = function() {
                    myFactory.loadingShow(); //显示加载圈
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "itemId-token-timestamp";
                    var signStr = "itemId=" + itemId + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'GET',
                        url: app.domain + 'input/initContentItem.action',
                        params: { 'itemId': itemId, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            $scope.chdrnum01 = response.data.data.policy.base.chdrnum01;
                            //$scope.item35=response.data.data.modelMap.item35;//后台这里原本就没有返回item35对象的数据
                            //item=$scope.item35;
                            item10 = response.data.data.modelMap.item10;
                            isOneYearCrtFlag = response.data.data.modelMap.isOneYearCrtFlag;
                            taxBenefitRole = response.data.data.modelMap.taxBenefitRole;
                            taxClientNo = response.data.data.modelMap.taxClientNo;
                            policy = response.data.data.policy;

                            //	国籍数据来源
                            /****** 把国籍信息装载在availableTags下拉框中 **********/
                            //国籍数据
                            //var nativesJson=response.data.data.modelMap.nativesJson;
                            var nativesJson = eval(response.data.data.modelMap.nativesJson);
                            //nativesJson={"label": "叙利亚 Syria","val": "SYR"};
                            //$scope.regionData = [];
                            $scope.countryData = nativesJson;

                            $scope.systemDate = response.data.data.modelMap.systemDate;
                            $scope.clientCount = item10.clientCount;

                            //数据绑定
                            var lenClient = item10.clientList.length;
                            console.log("lenClient:" + lenClient);
                            if (lenClient == 1) {
                                isCrsInsureFlag = true;
                            }
                            for (var i = 0; i < lenClient; i++) {
                                /*if(lenClient>1){//同时存在被保人和投保人的情况
	
							}else{//仅存在被保人或者投保人的情况
	
							}*/

                                var customerTypeTemp = item10.clientList[i].customerType;
                                $scope.reason = item10.reason;
                                if (customerTypeTemp == 'LF') { //被保人基本信息
                                    $scope.show10BbrFlag = true; //显示被保人界面
                                    $scope.customerType = item10.clientList[i].customerType;
                                    var idType = item10.clientList[i].idType; //3
                                    var availDataType = item10.clientList[i].availDataType;
                                    var marryd = item10.clientList[i].marryd;

                                    $scope.nameLF = item10.clientList[i].name;
                                    $scope.birthDayLF = item10.clientList[i].birthDay;
                                    var birthDayLF = item10.clientList[i].birthDay;
                                    //$("#birthDayLF").val($scope.birthDayLF);
                                    //myFactory.initDateUtil('birthDayLF','选择出生年月日',birthDayLF);
                                    myFactory.initDateUtil('birthDayLF', birthDayLF);

                                    var sex = item10.clientList[i].sex;
                                    if (sex == 'M') { //男
                                        $scope.data.radioFlagLF = true;
                                        sexLF = 'M';
                                    } else if (sex == 'F') { //女
                                        $scope.data.radioFlagLF = false;
                                        sexLF = 'F';
                                    }

                                    $scope.nativePlaceNameLF = item10.clientList[i].nativePlaceName;
                                    //$scope.nativePlaceLF=item10.clientList[i].nativePlace;
                                    var nativePlaceLF = item10.clientList[i].nativePlace;
                                    $("#nativePlaceLF").val(nativePlaceLF);
                                    nativePlaceLFBefore = nativePlaceLF; //CRS记录国籍是否变化

                                    $("#idTypeLF").val(idType);
                                    var options = $("#idTypeLF option:selected");
                                    //console.log("test11:"+options.val());
                                    //console.log("test22:"+options.text());
                                    $scope.idTypeNameLF = options.text();
                                    $("#oldIdTypeLF").val(idType);

                                    $scope.idNoLF = item10.clientList[i].idNo;

                                    $("#availDataTypeLF").val(availDataType);
                                    var options_avail = $("#availDataTypeLF option:selected");
                                    $scope.availDataTypeNameLF = options_avail.text();

								//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
								$scope.availDataStartLF=item10.clientList[i].availDataStart;
								var availDataStartLF=item10.clientList[i].availDataStart;
								myFactory.initDateUtil('availDataStartLF',availDataStartLF);
								//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end 
                                    $scope.availDataCloseLF = item10.clientList[i].availDataClose;
                                    var availDataCloseLF = item10.clientList[i].availDataClose;
                                    //if(availDataCloseLF!=''){
                                    //}
                                    myFactory.initDateUtil('availDataCloseLF', availDataCloseLF);

                                    if ($.trim(marryd) == "") {
                                        marryd = "M";
                                    }
                                    $("#marrydLF").val(marryd);
                                    var options_marryd = $("#marrydLF option:selected");
                                    $scope.marryStateNameLF = options_marryd.text();

                                    //证件有效期类型改变时
                                    $scope.onIdDateTypeChange("LF");

                                    //未被修改过的被保人基本信息
                                    orignInsuredInfo = {
                                        name: $scope.nameLF,
                                        birthDay: $scope.birthDayLF,
                                        sex: sexLF,
                                        nativePlaceName: nativePlaceLF,
                                        idType: idType,
                                        idNo: $scope.idNoLF,
                                        availDataType: availDataType,
										//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
										availDataStart:availDataStartLF,
										//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                                        availDataClose: availDataCloseLF,
                                        marryd: marryd
                                    };

                                } else if (customerTypeTemp == 'OW') { //投保人基本信息
                                    $scope.show10TbrFlag = true; //显示投保人界面
                                    //判断是否是同一个人 add by csf 20181219 start
                                    isSamePerson = false;
                                    //判断是否是同一个人 add by csf 20181219 end
                                    $scope.customerType = item10.clientList[i].customerType;
                                    var idType = item10.clientList[i].idType; //3
                                    var availDataType = item10.clientList[i].availDataType;
                                    var marryd = item10.clientList[i].marryd;

                                    $scope.nameOW = item10.clientList[i].name;
                                    $scope.birthDayOW = item10.clientList[i].birthDay;
                                    var birthDayOW = item10.clientList[i].birthDay;
                                    //myFactory.initDateUtil('birthDayOW','选择出生年月日',birthDayOW);
                                    myFactory.initDateUtil('birthDayOW', birthDayOW);

                                    var sex = item10.clientList[i].sex;
                                    if (sex == 'M') { //男
                                        $scope.data.radioFlagOW = true;
                                        sexOW = 'M';
                                    } else if (sex == 'F') { //女
                                        $scope.data.radioFlagOW = false;
                                        sexOW = 'F';
                                    }

                                    $scope.nativePlaceNameOW = item10.clientList[i].nativePlaceName;
                                    //$scope.nativePlaceOW=item10.clientList[i].nativePlace;
                                    var nativePlaceOW = item10.clientList[i].nativePlace;
                                    $("#nativePlaceOW").val(nativePlaceOW);
                                    nativePlaceOWBefore = nativePlaceOW; //CRS记录国籍是否变化

                                    $("#idTypeOW").val(idType);
                                    var options = $("#idTypeOW option:selected");
                                    //console.log("test11:"+options.val());
                                    //console.log("test22:"+options.text());
                                    $scope.idTypeNameOW = options.text();
                                    $("#oldIdTypeOW").val(idType);

                                    $scope.idNoOW = item10.clientList[i].idNo;

                                    $("#availDataTypeOW").val(availDataType);
                                    var options_avail = $("#availDataTypeOW option:selected");
                                    $scope.availDataTypeNameOW = options_avail.text();

								//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
								$scope.availDataStartOW=item10.clientList[i].availDataStart;
								
								var availDataStartOW=item10.clientList[i].availDataStart;
								
								myFactory.initDateUtil('availDataStartOW',availDataStartOW);
								//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                                    $scope.availDataCloseOW = item10.clientList[i].availDataClose;

                                    var availDataCloseOW = item10.clientList[i].availDataClose;
                                    //if(availDataCloseOW!=''){
                                    //}
                                    myFactory.initDateUtil('availDataCloseOW', availDataCloseOW);

                                    if ($.trim(marryd) == "") {
                                        marryd = "M";
                                    }
                                    $("#marrydOW").val(marryd);
                                    var options_marryd = $("#marrydOW option:selected");
                                    $scope.marryStateNameOW = options_marryd.text();

                                    //证件有效期类型改变时
                                    $scope.onIdDateTypeChange("OW");
                                }

                                /*if(provinceTemp[i].dutyname == prov){
                                	console.log(':'+prov+"provinceTemp[i].dutycode:"+provinceTemp[i].dutycode);
                                	$scope.selectedProvince=provinceTemp[i].dutycode;
                                	province = {"dutycode":provinceTemp[i].dutycode, "dutyname":provinceTemp[i].dutyname}
                                }*/
                            }
                            initFlag = true; //标识初始化成功
                        }
                        myFactory.loadingHide();
                    }, function errorCallback(response) {
                        myFactory.loadingHide();
                        myFactory.alert("", "初始化查询变更项内容失败!", "info");
                    });
                }
                /**********************************************初始化函数end****************************************************/
                //重新受理
            $scope.renew = function() {
                    myFactory.renew();
                }
                //退出移动保全
            $scope.exit = function() {
                    myFactory.exit();
                }
                //返回上一页
            $scope.goBack = function() {
                myFactory.goBack();
            }

            //性别单选按钮样式控制
            $scope.isLabelLF = function() {
                $scope.data.radioFlagLF = true;
                sexLF = 'M';
                console.log("data.radioFlagLF:" + $scope.data.radioFlagLF);
                $scope.detectionMatching('LF');
            }
            $scope.notLabelLF = function() {
                $scope.data.radioFlagLF = false;
                sexLF = 'F';
                console.log("data.radioFlagLF:" + $scope.data.radioFlagLF);
                $scope.detectionMatching('LF');
            }
            $scope.isLabelOW = function() {
                $scope.data.radioFlagOW = true;
                sexOW = 'M';
                $scope.detectionMatching('OW');
            }
            $scope.notLabelOW = function() {
                $scope.data.radioFlagOW = false;
                sexOW = 'F';
                $scope.detectionMatching('OW');
            }

            //证件选择弹框
            $scope.certificateChose = function() {
                modal('open', 'certificate_model', 'overwindow');
            }
            $scope.certificateClose = function() {
                modal('close', 'certificate_model', 'overwindow');
            }
            $scope.certificateClick = function(id) {
                $scope.data.certificateChoseId = id;
            }

            //选择身份证带出中国国籍
            $scope.defaultNationality = function(type) {
                var options = "";
                if (type == 'LF') {
                    options = $("#idTypeLF option:selected");
                    $scope.idTypeNameLF = options.text();
                } else if (type == 'OW') {
                    options = $("#idTypeOW option:selected");
                    $scope.idTypeNameOW = options.text();
                }
                console.log("val:" + options.val());
                console.log("text:" + options.text());

                tj = true;
                var v_jf = $("#idType" + type).val();

                $scope.detectionMatching(type);
                $scope.getBirthdatByIdNo(type);

                if (v_jf == 1) {
                    $("#nativePlaceName" + type).val("中国 China");
                    $("#nativePlaceSelect" + type).val("CHN"); //国籍设为中国
                    $("#nativePlace" + type).val("CHN"); //国籍设为中国
                    //$("#nativePlaceName"+type).attr("readonly","readonly");
                    $("#nativePlaceSelect" + type).attr("disabled", true);
                } else {
                    //$("#nativePlaceName"+type).attr("readonly",false);
                    $("#nativePlaceSelect" + type).attr("disabled", false);
                }
            }

            //检查日期、性别是否与身份证号匹配
            $scope.detectionMatching = function(type) {
                //function detectionMatching(type){
                tj = true;
                var isid = $("#idType" + type).val();

                if (isid == 1 || isid == 7) {
                    //身份证号
                    var iIdNo = document.getElementById("idNo" + type).value;
                    //性别
                    //var iSex=document.getElementById("sex"+type).value;
                    var iSex = "";
                    if (type == 'LF') {
                        var iSexFlag = $scope.data.radioFlagLF;
                        if (iSexFlag) { //男
                            iSex = "M"
                        } else {
                            iSex = "F"
                        }
                    } else if (type == 'OW') {
                        var iSexFlag = $scope.data.radioFlagOW;
                        if (iSexFlag) { //男
                            iSex = "M"
                        } else {
                            iSex = "F"
                        }
                    }

                    //出身年月日
                    var iDate = $("#birthDay" + type).val();

                    if ((iIdNo != "" || iIdNo != null) && (iIdNo.length == 15) || (iIdNo.length == 18)) {
                        //身份证号包含的出生年月日
                        var iIdDate = "";
                        if (iIdNo.length == 15) {
                            iIdDate = iIdNo.substring(6, 12);
                            iIdDate = "19" + iIdDate;
                            iIdDate = iIdDate.substring(0, 4) + "-" + iIdDate.substring(4, 6) + "-" + iIdDate.substring(6)
                        } else {
                            iIdDate = iIdNo.substring(6, 14);
                            iIdDate = iIdDate.substring(0, 4) + "-" + iIdDate.substring(4, 6) + "-" + iIdDate.substring(6)
                        }

                        var test = iIdNo.substr(iIdNo.length - 2, 1);

                        if (test % 2 != 0) {
                            test = "M";
                        }
                        if (test % 2 == 0) {
                            test = "F";
                        }
                        if (test != iSex) {
                            strReturn = "证件号码与性别不匹配，请重新确认 ！";
                            //$("#idNo"+type).testRemind(strReturn);
                            tj = false;
                            prompt = "证件号码与性别不匹配，请重新确认！";
                            myFactory.alert('', strReturn, 'info');
                        } else if (iDate != iIdDate) {
                            strReturn = "证件号码与出生日期不匹配，请重新确认！ ！";
                            //$("#idNo"+type).testRemind(strReturn);
                            tj = false;
                            prompt = "证件号码与出生日期不匹配，请重新确认！";
                            myFactory.alert('', strReturn, 'info');
                        }
                    } else {
                        strReturn = "证件号码错误，请重新确认！ ！";
                        //$("#idNo"+type).testRemind(strReturn);
                        tj = false;
                        prompt = "证件号码错误，请重新确认！";
                        myFactory.alert('', strReturn, 'info');
                    }
                }
                return tj;

            }

            //输入身份证号带出出生日期判断性别是否正确
            $scope.getBirthdatByIdNo = function(type) {
                //function getBirthdatByIdNo(type) {
                tj = true;
                var isid = $("#idType" + type).val();
                //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
                $("#idNo" + type).val(document.getElementById("idNo" + type).value.toUpperCase());
                if (isid == 1 || isid == 7) {
                    var iIdNo = document.getElementById("idNo" + type).value.toUpperCase();
                    //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end

                    var tmpStr = "";
                    var idDate = "";
                    var tmpInt = 0;
                    var strReturn = "";
                    if (isid == 1) {
                        if ((iIdNo.length != 15) && (iIdNo.length != 18)) {
                            strReturn = "证件号码不正确，请重新确认！ ";
                            //$("#idNo"+type).testRemind(strReturn);
                            tj = false;
                            prompt = "证件号码不正确，请重新确认！";
                            myFactory.alert('', strReturn, 'info');
                            return tj;
                        }
                    } else if (isid == 7) {
                        if (iIdNo.length != 18) {
                            strReturn = "证件类型为户口本时，证件号码位数应为18位，请重新确认！ ！";
                            //$("#idNo"+type).testRemind(strReturn);
                            tj = false;
                            prompt = "证件类型为户口本时，证件号码位数应为18位，请重新确认！";
                            myFactory.alert('', strReturn, 'info');
                            return tj;
                        }
                    }
                    if (iIdNo.length == 15) {
                        tmpStr = iIdNo.substring(6, 12);
                        tmpStr = "19" + tmpStr;
                        tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6)
                        $("#birthDay" + type).val(tmpStr);

                        //myFactory.initDateUtil('birthDayLF','选择出生年月日',tmpStr);//再次初始化日期没有用的，跟以前的动态改变日期不一样
                        myFactory.setDateUtil("birthDay" + type, tmpStr);

                        if ($("#birthDay" + type).val() == "") {
                            strReturn = "证件号码不正确，请重新确认！";
                            //$("#idNo"+type).testRemind(strReturn);
                            tj = false;
                            prompt = "证件号码不正确，请重新确认！";
                            myFactory.alert('', strReturn, 'info');
                            return tj;
                        }
                    } else {
                        tmpStr = iIdNo.substring(6, 14);
                        tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6)
                        $("#birthDay" + type).val(tmpStr);

                        //myFactory.initDateUtil('birthDayLF','选择出生年月日',tmpStr);
                        myFactory.setDateUtil("birthDay" + type, tmpStr);

                        var is_fandm = iIdNo.substring(16, 17);
                        //设置性别
                        if (is_fandm % 2 == 1) { //男 
                            $scope.data["radioFlag" + type] = true;
                            if (type == "LF") {
                                sexLF = 'M';
                            } else if (type == "OW") {
                                sexOW = 'M';
                            }
                        } else if (is_fandm % 2 == 0) { //女
                            $scope.data["radioFlag" + type] = false;
                            if (type == "LF") {
                                sexLF = 'F';
                            } else if (type == "OW") {
                                sexOW = 'F';
                            }
                        }

                        if ($("#birthDay" + type).val() == "") {
                            strReturn = "证件号码不正确，请重新确认！";
                            //$("#idNo"+type).testRemind(strReturn);
                            tj = false;
                            prompt = "证件号码不正确，请重新确认！";
                            myFactory.alert('', strReturn, 'info');
                            return tj;
                        }
                    }
                }
                if (tj) {
                    var flag = $scope.detectionMatching(type);
                    if (flag) {
                        //checkDateType(type);
                        var checkDateTypeFlag = checkDateType(type);
                        return checkDateTypeFlag;
                    }
                }
                return tj;
            }

            //证件类型为身份证时，45岁（含）以下证件有效期不可为终身   modify by liangdan 20160406
            function checkDateType(type) {
                tj = true;
                var isid = $("#idType" + type).val(); //证件类型
                var _availDataType = $("#availDataType" + type).val(); //	投保人或被保人有效期类型
                if (isid == 1 && _availDataType == 1) { //身份证
                    var iDate = $("#birthDay" + type).val(); //出生日期1995-07-08
                    if (iDate != "" || iDate != null) {
                        var age = getAge(iDate);
                        if (age <= 45) {
							/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
							strReturn = "45岁（含）以下有效期类型不可为长期，请重新确认！ ！";
							tj=false;
							prompt="45岁（含）以下有效期类型不可为长期，请重新确认！ ！";
							/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
                            //$("#availDataTypeMsg"+type).testRemind(strReturn);
                            myFactory.alert('', strReturn, 'info');
                            return tj;
                        }
                    }
                }
                return tj;
            }

            /*根据出生日期算出年龄*/
            function getAge(strBirthday) {
                var returnAge;
                var strBirthdayArr = strBirthday.split("-");
                var birthYear = strBirthdayArr[0];
                var birthMonth = strBirthdayArr[1];
                var birthDay = strBirthdayArr[2];

                d = new Date();
                var nowYear = d.getFullYear();
                var nowMonth = d.getMonth() + 1;
                var nowDay = d.getDate();

                if (nowYear == birthYear) {
                    returnAge = 0; //同年 则为0岁  
                } else {
                    var ageDiff = nowYear - birthYear; //年之差  
                    if (ageDiff > 0) {
                        if (nowMonth == birthMonth) {
                            var dayDiff = nowDay - birthDay; //日之差  
                            if (dayDiff < 0) {
                                returnAge = ageDiff - 1;
                            } else {
                                returnAge = ageDiff;
                            }
                        } else {
                            var monthDiff = nowMonth - birthMonth; //月之差  
                            if (monthDiff < 0) {
                                returnAge = ageDiff - 1;
                            } else {
                                returnAge = ageDiff;
                            }
                        }
                    } else {
                        returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天  
                    }
                }
                return returnAge; //返回周岁年龄  
            }
            
            //S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
			//外国人永久居留身份证校验
			function checkCardToA(card,birthday,sex){
				var len = card.length;
				if(len!=15 && len!=18){//校验长度
					return false;
				}
				var letterReg = /^[a-zA-Z]{3}\d{12}$/;
				var numberReg = /^[0-9]*$/;
				if(len==15){
					if (!letterReg.test(card)) {
						return false;
					}
				}
				if(len==18){
					var num1 = card.substring(0, 1);//第1位，必须为9开头
					var num7 = card.substring(6, 14);//第7-14位，判断出生日期
					var num17 = card.substring(16, 17);//第17位，判断性别
				    if (!numberReg.test(card) || num1!="9") {
						return false;
					}
				    birthday = birthday.replaceAll('-', '');

					if(birthday!=num7){
						return false;
					}
					if((num17%2)==0){
						//偶数--女性
						if(sex!="F"){
							return false;
						}
					}else{
						//奇数--男性
						if(sex!="M"){
							return false;
						}
					}
				}
				return true;
			};
			
			function changeAvailDataStart(dataStart,dataEnd,birthDay){
				dataStart = dataStart.replaceAll('-', '');
				dataEnd=dataEnd.replaceAll('-', '');
				birthDay=birthDay.replaceAll('-', '');
				//计算年龄（有效期起始日-出生日期）
				var age = getTimeDifference(dataStart,birthDay);
				
				//截止日+1天
				var dataEndT = new Date(dataEnd.substring(0,4)+'/'+dataEnd.substring(4,6)+'/'+dataEnd.substring(6,8));
				dataEndT = new Date(dataEndT.getTime() + 24*60*60*1000);
				var endYear = dataEndT.getFullYear();
				var endMonth = dataEndT.getMonth() + 1;  
				var endDay = dataEndT.getDate();
				endMonth = endMonth < 10 ? '0' + endMonth : endMonth;
	            endDay = endDay < 10 ? '0' + endDay : endDay;
				var endMD = endMonth.toString() + endDay.toString();
				var dataEndDateTStr = endYear.toString() + endMD;
				var period = getTimeDifference(dataEndDateTStr,dataStart);
				
				if(age<18){
					if(period!=5){
						return false;
					}
				}else{
					if(period!=10){
						return false;
					}
				}

				var dataStartMD = dataStart.substring(4,8);
				var dataEndMD = dataEnd.substring(4,8);
				if(dataStartMD!="0229" && dataEndMD!="0229"){		
					if(dataStartMD!=dataEndMD && dataStartMD!=endMD){
						return false;
					}				
				}
				return true;
			}
			
			function getTimeDifference(dataStart,dataEnd){         
				var returnYear;  
				
				dataStart = dataStart.replaceAll('-', '');
				var dataStartYear = dataStart.substring(0,4); 
				var dataStartMonth = dataStart.substring(4,6);   
				var dataStartDay = dataStart.substring(6,8); 
				
				dataEnd=dataEnd.replaceAll('-', '');
				var dataEndYear = dataEnd.substring(0,4); 
				var dataEndMonth = dataEnd.substring(4,6);
				var dataEndDay = dataEnd.substring(6,8);
				
				if(dataStartYear == dataEndYear){  
					returnYear = 0;//同年
				} else {  
					var yearDiff = dataStartYear - dataEndYear ; //年之差  
					if(yearDiff > 0){  
						if(dataStartMonth == dataEndMonth) {  
							var dayDiff = dataStartDay - dataEndDay;//日之差  
							if(dayDiff < 0) {  
								returnYear = yearDiff - 1;  
							} else {  
								returnYear = yearDiff ;  
							}  
						} else {  
							var monthDiff = dataStartMonth - dataEndMonth;//月之差  
							if(monthDiff < 0) {  
								returnYear = yearDiff - 1;  
							} else {  
								returnYear = yearDiff ;  
							}  
						}  
					} else {  
						returnYear = -1;//返回-1 表示日期输入错误
					}  
				}  
				return returnYear;
			} 
			//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end

            $scope.marrydLFSelect = function() {
                var options = $("#marrydLF option:selected");
                console.log("test111:" + options.val());
                console.log("test222:" + options.text());
                $scope.marryStateNameLF = options.text();
            }

            $scope.marrydOWSelect = function() {
                var options = $("#marrydOW option:selected");
                $scope.marryStateNameOW = options.text();
            }

            $scope.changeNativePlaceLF = function() {
                var options = $("#nativePlaceSelectLF option:selected");
                console.log("LF国籍id:" + options.val());
                console.log("LF国籍val:" + options.text());
                $scope.nativePlaceNameLF = options.text();
                $("#nativePlaceLF").val(options.val());
            }

            $scope.changeNativePlaceOW = function() {
                var options = $("#nativePlaceSelectOW option:selected");
                console.log("OW国籍id:" + options.val());
                console.log("OW国籍val:" + options.text());
                $scope.nativePlaceNameOW = options.text();
                $("#nativePlaceOW").val(options.val());
            }

            //证件有效期类型改变时
            $scope.onIdDateTypeChange = function(type) {
                tj = true;
                var options = "";
                if (type == 'LF') {
                    options = $("#availDataTypeLF option:selected");
                    $scope.availDataTypeNameLF = options.text();
                } else if (type == 'OW') {
                    options = $("#availDataTypeOW option:selected");
                    $scope.availDataTypeNameOW = options.text();
                }
                console.log("availDataType val:" + options.val());
                console.log("availDataType text:" + options.text());

                var _availDataType = options.val();
                //var _availDataType =$("#availDataType"+type);	//	投保人或被保人有效期类型
                //var _availDataClose=$("#availDataClose"+type);	//	投保人或被保人有效期截止日

                //initDate(_availDataClose); 
                //	有效期类型为[缺省]或[终身]时，设置有效期截止日为空值且不可修改
                if (_availDataType == '1' || _availDataType == '3') {
                    //_availDataClose.val("");
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					//$("#availDataStart"+type).attr("disabled",true);
					if(type=='LF'){
						$scope.availDataCloseLF="";
					}else if(type=='OW'){
						$scope.availDataCloseOW="";
						
					}
					$("#availDataClose"+type).val("");
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                    //_availDataClose.mobiscroll('disable');
                    $("#availDataClose" + type).attr("disabled", true);
                } else if (_availDataType == '2') {
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					$("#availDataStart"+type).attr("disabled",false);
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                    $("#availDataClose" + type).attr("disabled", false);
                }

                var checkDateTypeFlag = checkDateType(type);
                return checkDateTypeFlag;

            }

            //出生日期不能大于当前日期
            $scope.birthDayContrast = function(type) {
                tj = true;
                var systemDate = $scope.systemDate;
                var a = document.getElementById("birthDay" + type).value; //	投保人或被保人有效期截止日
                //a= $.trim(a);
                if ($.trim(a) > systemDate) {
                    //$("#birthDay"+type).testRemind("出生日期不能大于当前日期，请确认后填写！");
                    //$("#birthDay"+type).val(birthdate);
                    tj = false;
                    prompt = "出生日期不能大于当前日期，请确认后填写！";
                    myFactory.alert('', '出生日期不能大于当前日期，请确认后填写！', 'info');
                    return false;
                }
                //$scope.detectionMatching(type);
                var detectionMatchingFlag = $scope.detectionMatching(type);
                return detectionMatchingFlag;
            }

            //有效期截止日不能小于当前日期
            $scope.dateContrast = function(type) {
                tj = true;
                var systemDate = $scope.systemDate;
                //var a=document.getElementById("availDataClose"+type).value;	//	投保人或被保人有效期截止日
                var a = $("#availDataClose" + type).val();
                //a= $.trim(a);
                var _availDataType = $("#availDataType" + type).val(); //	投保人或被保人有效期类型
                if (_availDataType == 2) { //年期
                	//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 update by huanghk 20231116 start
                    if ($.trim(a) <= systemDate) {
                        //$("#availDataClose"+type).testRemind("有效期截止日不能小于当前日期，请确认后填写！");
                        tj = false;
                        var typename = "被保险人";
                        if("OW"==type){
            							typename = "投保人";
            						}
                        prompt = typename+"证件有效期截止日不能小于当前日期，请确认后填写！";
                        myFactory.alert('', typename+'证件有效期截止日不能小于当前日期，请确认后填写！', 'info');
                        return tj;
                    }
                    //S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 update by huanghk 20231116 end
                }
                return tj;
            }
			// S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
			$scope.dateContrastStart = function(type){
				tj=true;
				var systemDate=$scope.systemDate;
				//var a=document.getElementById("availDataClose"+type).value;	//	投保人或被保人有效期截止日
				var a=$("#availDataStart"+type).val();
				var birth="";
				if(type=="LF"){
					birth=$("#birthDayLF").val();
				}else{
					birth=$("#birthDayOW").val();
				}
				var _availDataType =$("#availDataType"+type).val();	//	投保人或被保人有效期类型
				
					if($.trim(a)<birth){
						tj=false;
						prompt="有效期起始日必须大于出生日期，请确认后填写！";
						myFactory.alert('','有效期起始日必须大于出生日期，请确认后填写！','info');
						return tj;
					}
					if($("#idTypeMsgLF").val() =="1" && type=="LF"){
						if($.trim(a)<'2004-03-29'){
							tj=false;
							prompt="当证件类型为“身份证”，“有效期起始日”必须大于等于2004年3月29日（二代身份证启用日）。请确认后填写！";
							myFactory.alert('','当证件类型为“身份证”，“有效期起始日”必须大于等于2004年3月29日（二代身份证启用日）。请确认后填写！','info');
							return tj;
						}
				    }
					if($("#idTypeMsgOW").val() =="1" && type=="OW"){
						if($.trim(a)<'2004-03-29'){
							tj=false;
							prompt="当证件类型为“身份证”，“有效期起始日”必须大于等于2004年3月29日（二代身份证启用日）。请确认后填写！";
							myFactory.alert('','当证件类型为“身份证”，“有效期起始日”必须大于等于2004年3月29日（二代身份证启用日）。请确认后填写！','info');
							return tj;
						}
				    }
					if($.trim(a)>systemDate){  
						tj=false;
						prompt="有效期起始日必须少于等于当前日，请确认后填写！";
						myFactory.alert('','有效期起始日必须少于等于当前日，请确认后填写！','info');
						return tj;
					}
				
				return tj;
			}
			//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
            //下一步
            $scope.nextStep = function() {
                //判断是否初始化完成了，如果失败，不予进入下一步
                if (!initFlag) {
                    myFactory.alert("", "初始化时失败，请返回上一步重试", "info");
                    return;
                }

                //数据校验：
                var _idTypeOW = $("#idTypeOW").val(); //	当前：证件类型(投保人)
                var _idTypeLF = $("#idTypeLF").val(); //	当前：证件类型(被保人)
                var _oldIdTypeOW = $("#oldIdTypeOW").val(); //	历史：证件类型(投保人)
                var _oldIdTypeLF = $("#oldIdTypeLF").val(); //	历史：证件类型(被保人)

                var _availDataTypeOW = $("#availDataTypeOW").val(); //	当前：证件有效期类型(投保人)
                var _availDataTypeLF = $("#availDataTypeLF").val(); //	当前：证件有效期类型(被保人)
                var _oldAvailDataTypeOW = $("#oldAvailDataTypeOW").val(); //	历史：证件有效期类型(投保人)
                var _oldAvailDataTypeLF = $("#oldAvailDataTypeLF").val(); //	历史：证件有效期类型(被保人)
		    	//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
		    	var _availDataStartOW = $("#availDataStartOW").val();  //证件有效期起始日
		    	var _availDataStartLF = $("#availDataStartLF").val();  //证件有效期起始日
		    	//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end 
                var _availDataCloseOW = $("#availDataCloseOW").val(); //	证件有效期截止日(投保人)
                var _availDataCloseLF = $("#availDataCloseLF").val(); //	证件有效期截止日(被保人)

                //数据
                var nameLFTemp = $("#nameLF").val(); //客户姓名
                var nativePlaceLFTemp = $("#nativePlaceLF").val();
                var nativePlaceNameLFTemp = $("#nativePlaceNameLF").val();
                var idTypeLFTemp = $("#idTypeLF").val();
                var idNoLFTemp = $("#idNoLF").val();

                var birthDayLFTemp = $("#birthDayLF").val();
                var sexLFTemp = sexLF;
                var availDataTypeLFTemp = $("#availDataTypeLF").val();
                var availDataCloseLFTemp = $("#availDataCloseLF").val();
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				var availDataStartLFTemp=$("#availDataStartLF").val();   
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                var marrydLFTemp = $("#marrydLF").val();

                var reasonTemp = $("#reason").val();

                if (nameLFTemp == null || nameLFTemp.trim() == "") {
                    myFactory.alert("", "请输入姓名", "info");
                    return;
                }

                if (nativePlaceLFTemp == null || nativePlaceLFTemp.trim() == "" || nativePlaceLFTemp == undefined) {
                    myFactory.alert("", "请选择国籍", "info");
                    return;
                }

                /******************************************
                 * [证件类型]数据逻辑校验
                 *    1.如果该栏位值有变动时不允许录入[0-漏填]值
                 *    2.历史值为空或0时都以[0-漏填]来处理做判断
                 ******************************************/
                if (_idTypeLF == "0" || _idTypeLF == null || _idTypeLF.trim() == "") {
                    /* 开放历史证件类型数据校验  add by wyf 2017-2-14 */
                    /*if( _oldIdTypeLF != "0" && _oldIdTypeLF != "" ){*/
                    //$("#idTypeMsgLF").testRemind("证件类型录入有误，请重新确认！");
                    myFactory.alert('', '证件类型录入有误，请重新确认！', 'info');
                    return false;
                    /*}*/
                }

                //证件类型为“外国人永久居留身份证”时，有效类型不能为终身
                if (_idTypeLF == "A" && _availDataTypeLF == "1") {
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 start
					myFactory.alert('',"外国人永久居留身份证有效期类型不可选择长期",'info');
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 end
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
                    return false;
                }

                if (idNoLFTemp == null || idNoLFTemp.trim() == "") {
                    myFactory.alert("", "被保险人证件号码不能为空", "info");
                    return;
                }
                
                //S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
				if(_idTypeLF =='A'){
					if(!checkCardToA(idNoLFTemp.trim(),birthDayLFTemp.trim(),sexLF)){
						myFactory.alert("","被保险人证件号码不正确，请重新确认","info");
						return;
					}
				}
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end

                /******************************************
                 * [有效期类型]数据逻辑校验
                 *    1.如果该栏位值有变动时不允许录入[3-缺省]值
                 *    2.历史值为空或3时都以[3-缺省]来处理做判断
                 *
                 ******************************************/
                if (_availDataTypeLF == "3" || _availDataTypeLF == null || _availDataTypeLF.trim() == "") {
                    /* 开放历史有效期类型数据校验  add by wyf 2017-2-14 */
                    /*if( _oldAvailDataTypeLF != "3" && _oldAvailDataTypeLF != "" ) {*/
                    //$("#availDataTypeMsgLF").testRemind("有效期类型录入有误，请重新确认！");
                    myFactory.alert('', '被保险人有效期类型录入有误，请重新确认！', 'info');
                    return false;
                    /*}*/
                }

                //选择年期时必须填写有效日日期
                if (_availDataTypeLF == "2" && _availDataCloseLF == "") {
                    //$("#availDataCloseLF").testRemind("请填写被保人有效期截止日！");
                    myFactory.alert('', '请填写被保险人有效期截止日！', 'info');
                    return false;
                }
                //S2019012807164 - 信易通OCR识别功能 add by csf 20190421 start
                if (_availDataTypeLF == "2" && !(new RegExp('(\\d){4}(-)(\\d){2}(-)(\\d){2}$', 'g').test(_availDataCloseLF))) {
                    myFactory.alert('', '证件有效期截止日格式错误，请重新输入！', 'info');
                    return;
                }
                //S2019012807164 - 信易通OCR识别功能 add by csf 20190421 end
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				if( _availDataTypeLF =="2" && _availDataStartLF == "" ){
					myFactory.alert('','请填写被保险人有效期起始日！','info');
					return false;
			   	}
				if( _availDataTypeLF =="2" && !(new RegExp('(\\d){4}(-)(\\d){2}(-)(\\d){2}$','g').test(_availDataStartLF))) {
					myFactory.alert('','证件有效期起始日格式错误，请重新输入！','info');
					return;
				}
				
				var _availDataType =$("#availDataTypeLF").val();	//	投保人或被保人有效期类型
				
					var a=$("#availDataStartLF").val();
					var birth=$("#birthDayLF").val();
					var systemDate=$scope.systemDate;
					if($.trim(a)<birth){
						prompt="有效期起始日必须大于出生日期，请确认后填写！";
						myFactory.alert('','有效期起始日必须大于出生日期，请确认后填写！','info');
						return;
					}
					if(_idTypeLF =="1" ){
						if($.trim(a)<'2004-03-29'){
							prompt="有效期起始日必须大于等于2004年3月29日（二代身份证启用日），请确认后填写！";
							myFactory.alert('','有效期起始日必须大于等于2004年3月29日（二代身份证启用日），请确认后填写！','info');
							return ;
						}
					}
					if($.trim(a)>systemDate){
						prompt="有效期起始日必须少于等于当前日，请确认后填写！";
						myFactory.alert('','有效期起始日必须少于等于当前日，请确认后填写！','info');
						return;
					}
				
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
				if(_idTypeLF =='A'){
					if(!changeAvailDataStart(_availDataStartLF,_availDataCloseLF,birth)){
						myFactory.alert("","您填写的被保险人证件有效期不正确，请按证件上的实际有效日期填写！","info");
				    	return;
					}
				}
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
				
				
                var item10Client = [];
                item10Client[0] = {
                    "name": nameLFTemp,
                    "birthDay": birthDayLFTemp,
                    "sex": sexLFTemp,
                    "nativePlace": nativePlaceLFTemp,
                    "nativePlaceName": nativePlaceNameLFTemp,
                    "idType": idTypeLFTemp,
                    "idNo": idNoLFTemp,
                    "availDataType": availDataTypeLFTemp,
                    "availDataClose": availDataCloseLFTemp,
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start 
                    "availDataStart": availDataStartLFTemp,
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                    "marryd": marrydLFTemp,
                    "reason": reasonTemp
                };

                //S2019012807164 - 信易通OCR识别功能 add by csf 20190419 start
                if ($scope.flagLF == "LF" && $scope.scanCardIdLF == idNoLFTemp) { //正面

                    var idCardParam = {
                        "itemId": "10",
                        "chdrnum": $scope.chdrnum01,
                        "role": $scope.flagLF,
                        "type": "0",
                        "idCardSmallPic": $scope.idCardSmallPicLF0,
                        "idCardBigPic": $scope.idCardBigPicLF0
                    };
                    $scope.saveIdCardCache(idCardParam);
                }
				/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210726 start*/
				if($scope.flagLF == "LF" &&($scope.scanCardDateLF == availDataCloseLFTemp||($scope.scanCardDateLF == "长期" && availDataCloseLFTemp==""))){//反面
				/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210726 end*/
                    var idCardParam = {
                        "itemId": "10",
                        "chdrnum": $scope.chdrnum01,
                        "role": $scope.flagLF,
                        "type": "1",
                        "idCardSmallPic": $scope.idCardSmallPicLF1,
                        "idCardBigPic": $scope.idCardBigPicLF1
                    };
                    $scope.saveIdCardCache(idCardParam);
                }
                //S2019012807164 - 信易通OCR识别功能 add by csf 20190419 end
                //检测被保人信息是否被改动，用原始方案，暂不改动逻辑了
                compareInsuredInfo(nameLFTemp, birthDayLFTemp, sexLFTemp, nativePlaceLFTemp, nativePlaceNameLFTemp,
                    idTypeLFTemp, idNoLFTemp, availDataTypeLFTemp, availDataCloseLFTemp, marrydLFTemp);

                var clientCount = $scope.clientCount;
                if (clientCount > 1) {
                    var nameOWTemp = $("#nameOW").val(); //客户姓名
                    var nativePlaceOWTemp = $("#nativePlaceOW").val();
                    var nativePlaceNameOWTemp = $("#nativePlaceNameOW").val();
                    var idTypeOWTemp = $("#idTypeOW").val();
                    var idNoOWTemp = $("#idNoOW").val();
                    var birthDayOWTemp = $("#birthDayOW").val();
                    var sexOWTemp = sexOW;
                    var availDataTypeOWTemp = $("#availDataTypeOW").val();
                    var availDataCloseOWTemp = $("#availDataCloseOW").val();
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					var availDataStartOWTemp=$("#availDataStartOW").val();
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                    var marrydOWTemp = $("#marrydOW").val();

                    if (nameOWTemp == null || nameOWTemp.trim() == "") {
                        myFactory.alert("", "请输入姓名", "info");
                        return;
                    }

                    if (nativePlaceOWTemp == null || nativePlaceOWTemp.trim() == "" || nativePlaceOWTemp == undefined) {
                        myFactory.alert("", "请选择国籍", "info");
                        return;
                    }

                    if (_idTypeOW == "0" || _idTypeOW == null || _idTypeOW.trim() == "") {
                        /* 开放历史证件类型数据校验  add by wyf 2017-2-14 */
                        /*if( _oldIdTypeOW != "0" && _oldIdTypeOW != "" ){*/
                        //$("#idTypeMsgOW").testRemind("证件类型录入有误，请重新确认！");
                        myFactory.alert('', '证件类型录入有误，请重新确认！', 'info');
                        return false;
                        /*}*/
                    }

                    if (_idTypeOW == "A" && _availDataTypeOW == "1") {
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
						//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 start
						myFactory.alert('',"外国人永久居留身份证有效期类型不可选择长期",'info');
						//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 end
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
                        return false;
                    }

                    if (idNoOWTemp == null || idNoOWTemp.trim() == "") {
                        myFactory.alert("", "投保人证件号码不能为空", "info");
                        return;
                    }
                    
                    //S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
					if(_idTypeOW =='A'){
						if(!checkCardToA(idNoOWTemp.trim(),birthDayOWTemp.trim(),sexOW)){
							myFactory.alert("","投保人证件号码不正确，请重新确认","info");
							return;
						}
					}
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end

                    if (_availDataTypeOW == "3" || _availDataTypeOW == null || _availDataTypeOW.trim() == "") {
                        /* 开放历史有效期类型数据校验  add by wyf 2017-2-14 */
                        /*if(  _oldAvailDataTypeOW != "3" && _oldAvailDataTypeOW != "" ){*/
                        //$("#availDataTypeMsgOW").testRemind("有效期类型录入有误，请重新确认！");
                        myFactory.alert('', '投保人有效期类型录入有误，请重新确认！', 'info');
                        return false;
                        /*}*/
                    }

                    //选择年期时必须填写有效日日期
                    if (_availDataTypeOW == "2" && _availDataCloseOW == "") {
                        //$("#availDataCloseOW").testRemind("请填写投保人有效期截止日！");
                        myFactory.alert('', '请填写投保人有效期截止日！', 'info');
                        return false;
                    }
                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190421 start
                    if (_availDataTypeOW == "2" && !(new RegExp('(\\d){4}(-)(\\d){2}(-)(\\d){2}$', 'g').test(_availDataCloseOW))) {
                        myFactory.alert('', '证件有效期截止日格式错误，请重新输入！', 'info');
                        return;
                    }
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					if( _availDataTypeOW =="2" && _availDataStartOW == "" ){
						myFactory.alert('','请填写投保人有效期起始日！','info');
						return false;
				   	}
					if( _availDataTypeOW =="2" && !(new RegExp('(\\d){4}(-)(\\d){2}(-)(\\d){2}$','g').test(_availDataStartOW))) {
						myFactory.alert('','证件有效期起始日格式错误，请重新输入！','info');
						return;
					}

					var _availDataType =$("#availDataTypeOW").val();	//	投保人或被保人有效期类型
					
						var a=$("#availDataStartOW").val();
						var birth=$("#birthDayOW").val();
						var systemDate=$scope.systemDate;
						if($.trim(a)<birth){
							prompt="有效期起始日必须大于出生日期，请确认后填写！";
							myFactory.alert('','有效期起始日必须大于出生日期，请确认后填写！','info');
							return;
						}
						if(_idTypeOW =="1" ){
							if($.trim(a)<'2004-03-29'){
								prompt="当证件类型为“身份证”，“有效期起始日”必须大于等于2004年3月29日（二代身份证启用日）。请确认后填写！";
								myFactory.alert('','当证件类型为“身份证”，“有效期起始日”必须大于等于2004年3月29日（二代身份证启用日）。请确认后填写！','info');
								return ;
							}
						}
						if($.trim(a)>systemDate){
							prompt="有效期起始日必须少于等于当前日，请确认后填写！";
							myFactory.alert('','有效期起始日必须少于等于当前日，请确认后填写！','info');
							return;
						}
					
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				    
				    //S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
					if(_idTypeOW =='A'){
						if(!changeAvailDataStart(_availDataStartOW,_availDataCloseOW,birth)){
							myFactory.alert("","您填写的投保人证件有效期不正确，请按证件上的实际有效日期填写！","info");
					    	return;
						}
					}
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
				
                    item10Client[1] = {
                        "name": nameOWTemp,
                        "birthDay": birthDayOWTemp,
                        "sex": sexOWTemp,
                        "nativePlace": nativePlaceOWTemp,
                        "nativePlaceName": nativePlaceNameOWTemp,
                        "idType": idTypeOWTemp,
                        "idNo": idNoOWTemp,
                        "availDataType": availDataTypeOWTemp,
                        "availDataClose": availDataCloseOWTemp,
						//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
						"availDataStart":availDataStartOWTemp,
						//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                        "marryd": marrydOWTemp,
                        "reason": reasonTemp
                    };

                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190419 end
                    if ($scope.flagOW == "OW" && $scope.scanCardIdOW == idNoOWTemp) {

                        var idCardParam = {
                            "itemId": "10",
                            "chdrnum": $scope.chdrnum01,
                            "role": $scope.flagOW,
                            "type": "0",
                            "idCardSmallPic": $scope.idCardSmallPicOW0,
                            "idCardBigPic": $scope.idCardBigPicOW0
                        };
                        $scope.saveIdCardCache(idCardParam);
                    }
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210726 start*/
					if($scope.flagOW == "OW" && ($scope.scanCardDateOW == availDataCloseOWTemp||($scope.scanCardDateOW == "长期" && availDataCloseOWTemp==""))){//反面
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210726 end*/	
                        var idCardParam = {
                            "itemId": "10",
                            "chdrnum": $scope.chdrnum01,
                            "role": $scope.flagOW,
                            "type": "1",
                            "idCardSmallPic": $scope.idCardSmallPicOW1,
                            "idCardBigPic": $scope.idCardBigPicOW1
                        };
                        $scope.saveIdCardCache(idCardParam);
                    }
                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190419 end
                }

                if (tj) {
                    checkDateType('OW');
                    checkDateType('LF');
                    var dateContrastFlag = $scope.dateContrast('LF'); ////有效期截止日不能小于当前日期
                    var birthDayContrastFlag = $scope.birthDayContrast('LF'); //出生日期不能大于当前日期
                    var getBirthdatByIdNoFlag = $scope.getBirthdatByIdNo('LF');
                    if (!dateContrastFlag || !birthDayContrastFlag || !getBirthdatByIdNoFlag) {
                        return false;
                    }
                    var dateContrastFlagOW = $scope.dateContrast('OW'); ////有效期截止日不能小于当前日期
                    var birthDayContrastFlagOW = $scope.birthDayContrast('OW'); //出生日期不能大于当前日期
                    var getBirthdatByIdNoFlagOW = $scope.getBirthdatByIdNo('OW');
                    if (!dateContrastFlagOW || !birthDayContrastFlagOW || !getBirthdatByIdNoFlagOW) {
                        return false;
                    }
                }

                if (tj == false) {
                    myFactory.alert('', prompt, 'info');
                    return false;
                }

                //var reason  = $("#reason").val();
                if (reasonTemp == "") {
                    myFactory.alert('', "请输入变更原因", 'info');
                    return false;
                }

                //S2019042908337营运系统反洗钱工作差异分析系统优化需求 add by yangyan 2019717 start
                if (reasonTemp.length >= 50) {
                    myFactory.alert('', "变更原因字数要小于50个", 'info');
                    return false;
                }
                //S2019042908337营运系统反洗钱工作差异分析系统优化需求 add by yangyan 2019717 end

                //检测查阅弹框
                var readImageFlag = $("#readImageFlag").val();
                if (readImageFlag == "false") {
                    /*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 start*/
                    /*myFactory.alert('',"请阅读《申请须知》！",'info');*/
                    //S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 start
                    myFactory.alert('', "请阅读《投保人和被保险人声明与授权事项》和《中信保诚隐私政策》！", 'info');
                    //S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 end
                    /*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 end*/
                    return;
                }
                // add by yinruirong 20180926 客户证件类型需新增“港澳居民居住证”和“台湾居民居住证” 校验规则 start
                /**************************
                 * 1.证件类型为港澳台居民居住证(810000或820000或830000开头的18位数)，国籍只能选"中国-香港"、"中国-澳门"、"中国台湾"
                 * 2.证件有效期类型不能选择终身
                 * 3.证件有效期不能为空
                 */

                var nativePlaceOWTemp = $("#nativePlaceOW").val(); //国籍(投保人)
                var idNoOWTemp = $("#idNoOW").val(); //证件号码(投保人)

                //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
                //				var re = /^\d{18}$/; //18位整数正则表达式
                var re = /^\d{18}$|^\d{17}X$/; //18位整数或者17位整数+X正则表达式
                //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end
                // 投保人
                if (_idTypeOW == "B" || _idTypeOW == "C") {
                    if (_idTypeOW == "B") {
                        if (!(re.test(idNoOWTemp) && (idNoOWTemp.substring(0, 6) == "810000" || idNoOWTemp.substring(0, 6) == "820000"))) {
                            myFactory.alert('', '港澳居民居住证不合法!', 'info');
                            return;
                        }
                    }
                    if (_idTypeOW == "C") {
                        if (!(re.test(idNoOWTemp) && idNoOWTemp.substring(0, 6) == "830000")) {
                            myFactory.alert('', '台湾居民居住证不合法!', 'info');
                            return;
                        }
                    }
                    //判断国籍与证件类型是否相符
                    if ((idNoOWTemp.substring(0, 6) == "810000" && nativePlaceOWTemp != 'HKG') ||
                        (idNoOWTemp.substring(0, 6) == "820000" && nativePlaceOWTemp != 'MAC') ||
                        (idNoOWTemp.substring(0, 6) == "830000" && nativePlaceOWTemp != 'TWN')) {
                        myFactory.alert('', '国籍与证件类型不符!', 'info');
                        return;
                    }
                    //港澳台居民居住证不能选择终身
                    if (_availDataTypeOW == "1") {
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
						myFactory.alert('','港澳台居民居住证不能选择长期','info');
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
                        return;
                    }
                    //有效期不能为空
                    if (_availDataCloseOW == null || _availDataCloseOW == "") {
                        myFactory.alert('', '证件有效期截止日不能为空', 'info');
                        return;
                    }
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					if(_availDataStartOW == null || _availDataStartOW == "") {
						myFactory.alert('','证件有效期起始日不能为空','info');
						return;
					}
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				}
				
				//被保人
				if(_idTypeLF == "B" || _idTypeLF == "C") {
					if(_idTypeLF == "B") {
						if(!(re.test(idNoLFTemp) && (idNoLFTemp.substring(0,6) == "810000" || idNoLFTemp.substring(0,6) == "820000"))) {
							myFactory.alert('','港澳居民居住证不合法!','info');
							return;
						}
					}
					if(_idTypeLF == "C") {
						if(!(re.test(idNoLFTemp) && idNoLFTemp.substring(0,6) == "830000")) {
							myFactory.alert('','台湾居民居住证不合法!','info');
							return;
						}
					}
					//判断国籍与证件类型是否相符
					if((idNoLFTemp.substring(0,6) == "810000" && nativePlaceLFTemp != 'HKG') || 
					   (idNoLFTemp.substring(0,6) == "820000" && nativePlaceLFTemp != 'MAC') || 
					   (idNoLFTemp.substring(0,6) == "830000" && nativePlaceLFTemp != 'TWN')) {
						myFactory.alert('','国籍与证件类型不符!','info');
						return;
					}
					//港澳台居民居住证不能选择终身
					if(_availDataTypeLF == "1") {
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
						myFactory.alert('','港澳台居民居住证不能选择长期','info');
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
						return;
					}
					//有效期不能为空
					if(_availDataCloseLF == null || _availDataCloseLF == "") {
						myFactory.alert('','证件有效期截止日不能为空','info');
						return;
					}
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					//有效期不能为空
					if(_availDataStartLF == null || _availDataStartLF == "") {
						myFactory.alert('','证件有效期起始日不能为空','info');
						return;
					}
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				}
				// add by yinruirong 20180926 客户证件类型需新增“港澳居民居住证”和“台湾居民居住证” 校验规则 end
		    	
				//将数据存入item对象
				item=item10Client;
				
				//CRS需求，增加个人税收页面  add by dll 2018-01-26 start
				if(!isOneYearCrtFlag){
					var nativeFlag = "";
					var nativePlaceIsChange = false;
					var taxName="";
					if(isCrsInsureFlag){//增加isCrsInsureFlag标识投保人和被保险人同一人，数据获取被保人的，因为身份信息栏位只显示被保人身份信息
						nativeFlag = $("#nativePlaceLF").val();
						if(nativePlaceLFBefore!=nativeFlag){//若国籍没变化，则无需填写CRS
							nativePlaceIsChange = true;//至少要国籍变化才需考虑CRS
						}
						taxName=policy.base.rnName;
					}else{
						nativeFlag = $("#nativePlaceOW").val();
						if(nativePlaceOWBefore!=nativeFlag){//若国籍没变化，则无需填写CRS
							nativePlaceIsChange = true;//至少要国籍变化才需考虑CRS
						}
						taxName=policy.base.surname;
					}
					//CRS个人税收居民身份保全需求 增加控制填写投保人、受益人单次填写问题 add by rqyang 2018-12-08 begin
					var holderCrsIsexistsFlag=sessionStorage.getItem("HOLDER_CRS_ISEXISTS_FLAG");
					if(nativePlaceIsChange && ""!=nativeFlag && nativeFlag!="CHN" && holderCrsIsexistsFlag=="N"){//&& nativeFlag!="HKG" && nativeFlag!="TWN" && nativeFlag!="MAC"
						//CRS个人税收居民身份保全需求 增加控制填写投保人、受益人单次填写问题 add by rqyang 2018-12-08 end
						$ionicHistory.clearCache().then(function(){
							$state.go('tax_info',{
								itemId:itemId,
								item:item,
								chdrnum:chdrnum01,
								chdrcoy:chdrcoy,
								taxBenefitRole:taxBenefitRole,
								taxClientNo:taxClientNo,
								taxName:taxName
							});
						 })
					}else{
						 $ionicHistory.clearCache().then(function(){
							 $state.go('content_check_main',{
							      itemId:itemId,item:item,chdrnum01:chdrnum01,chdrcoy:chdrcoy
						     });
						 })
					}
				}else{
					$ionicHistory.clearCache().then(function(){
						$state.go('content_check_main',{
							itemId:itemId,item:item,chdrnum01:chdrnum01,chdrcoy:chdrcoy
						});
					})
				}
				//CRS需求，增加个人税收页面  add by dll 2018-01-26 end

                //var param = {'bankcode':bankCode,'bankacctkey': bankNo,'city':bankCityCode,'paynmeFlag':accType,'flag':_flag,'beneClntNum':_beneClntNum};
                //params: {'bankcode':bankCode,'bankacctkey': bankNo,'city':bankCityCode,'paynmeFlag':accType,'flag':_flag,'beneClntNum':_beneClntNum},
                /*$http({
                	method: 'GET',
                	url: app.domain + 'charge/check.action',
                	params:{'bankcode':bankCode,'bankacctkey':bankNo}
                }).then(function successCallback(response) {
                	if (response.data == "fail") {
                		return;
                	}else{//校验成功
                		var sourceFlag = $("#sourceFlag").val();//页面来源
                		var item={
                			"name" : name,
                			"bankCityCode" : bankCityCode,
                			"bankCityName" : bankCityName,
                			"itemId" : itemId,
                			"reAccName" : accType,
                			"reBankAccNo" : bankNo,
                			"reBankCode" : bankCode,
                			"bankName" : bankName,
                			"sourceFlag" : sourceFlag,
                			"changeOther" :"",
                		}

                		//item["changeOther"] = "N";
                		$ionicHistory.clearCache().then(function(){
                			$state.go('content_check_main',{
                				itemId:itemId,
                				item:item,
                				chdrnum01:chdrnum01,
                				chdrcoy:chdrcoy
                			});
                		});


                	}
                }, function errorCallback(response) {
                	$.alert({
                		title: '',
                		text: '校验信息时发生错误!',
                		onOK: function () {
                			//点击确认
                		}
                	});
                });*/
            }

            //客户须知弹框
            $scope.tipOpen = function() {
                modal('open', 'tip_model', 'policyWindowOn10Input');
            }
            $scope.tipClose = function() {
                modal('close', 'tip_model', 'policyWindowOn10Input');
            }

            //S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 start
            $scope.privacyOpen = function() {
                    $state.go('privacy', {
                        itemId: itemId,
                        chdrnum01: chdrnum01,
                        chdrcoy: chdrcoy
                    });
                }
                //S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 end 
			//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
			$scope.jpgopen = function(){ 
				$state.go('jpgopen', {
                    itemId: itemId,
                    chdrnum01: chdrnum01,
                    chdrcoy: chdrcoy
                });
			}
			//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end

            //页面同意阅读协议复选框部分
            $scope.changeReadFlag = function() {
                    $scope.readFlag = !$scope.readFlag;
                }
                //保单详情
            $scope.showPolicyDetail = function() {
                modal('open', 'policyModalOn10Input', 'policyWindowOn10Input', 'policyCloseXOn10Input');
                var timestamp = myFactory.getTimetamp();
                var sfis = "chdrnum-chdrcoy-token-timestamp";
                var signStr = "chdrnum=" + chdrnum01 + "&chdrcoy=" + chdrcoy + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                var sign = myFactory.hex(signStr);
                //初始化查询订单详情
                var policyData;
                $http({
                    method: 'GET',
                    url: app.domain + 'query/restFindPolicyDetail.action',
                    params: { 'chdrnum': chdrnum01, 'chdrcoy': chdrcoy, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                }).then(function successCallback(response) {
                    if (response.data.success) {
                        policyData = response.data.data;
                        $scope.policyData = policyData;
                        $scope.policyData.ptdate01 = myFactory.DateTools($scope.policyData.ptdate01);
                    }
                }, function errorCallback(response) {
                    $.alert({
                        title: '',
                        text: '初始化查询订单详情失败!',
                        onOK: function() {
                            //点击确认
                        }
                    });
                });
            }

            //保单详情弹窗关闭
            $scope.policyCancelOn10Input = function() {
                modal('close', 'policyModalOn10Input', 'policyWindowOn10Input', 'policyCloseXOn10Input');
            }

            //关闭遮罩
            $scope.overwindowClose = function() {
                //$(".overwindow").show();
                $(".overwindow").hide();
                $(".overmodal").hide();
            }

            $scope.toContentInputTbr10 = function() {
                $ionicHistory.clearCache().then(function() {
                    $state.go('content_10_input_tbr', {
                        changeTypeId: itemId,
                        chdrnum01: chdrnum01,
                        chdrcoy: chdrcoy,
                        item10: item10
                    });
                })
            }

            //判断被保人的信息是否被修改过
            function compareInsuredInfo(nameLF, birthDayLF, sexLF, nativePlaceLF, nativePlaceNameLF,
                idTypeLF, idNoLF, availDataTypeLF, availDataCloseLF, marrydLF) {
                var changeInsuredInfo = {
                    name: nameLF,
                    birthDay: birthDayLF,
                    sex: sexLF,
                    nativePlaceName: nativePlaceLF,
                    idType: idTypeLF,
                    idNo: idNoLF,
                    availDataType: availDataTypeLF,
					    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
						availDataStart:availDataStartLF,
						//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                    availDataClose: availDataCloseLF,
                    marryd: marrydLF
                };
                var isChange = false;
                if (orignInsuredInfo != "" && orignInsuredInfo != null) {
                    for (var key in orignInsuredInfo) {
                        //被保人信息已经被更改
                        if (orignInsuredInfo[key] != changeInsuredInfo[key]) {
                            //将信息保存到浏览器的localstorage里进行存储 localstorage是h5新特性
                            //1-表示已经更改;0-表示没有更改 
                            //判断是否是同一个人 add by csf 20181219 start
                            if (!isSamePerson) {
                                //判断是否是同一个人 add by csf 20181219 end
                                sessionStorage.setItem("isChange_insured_item10", 1);
                                isChange = true;
                            }
                            console.log("被保人信息已经被更改!!!");
                            break;
                        }
                    }
                }
                if (!isChange) {
                    //没有更改
                    console.log("被保人信息没有被更改!!!");
                    sessionStorage.setItem("isChange_insured_item10", 0);
                }
            }

            /**
             * 扫描身份证信息
             */
            $scope.scanIDCardInfoItem10 = function(type, flag) { //type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                if ($scope.isPhotoOCRFlag) {
                    $scope.isPhotoOCRFlag = false;
                    setTimeout(function() {
                        $scope.isPhotoOCRFlag = true;
                    }, 350);
                } else {
                    return false;
                }
                //移动端
                cordova.sino.getIDCardInfo(function(result) {
                    if (result.success) {
                        if (!result.data.exit) {
                            if (appVersion === "IOS") {
                                if (result.data.ok) {
                                    //*********************************待开发逻辑代码区域begin**********************************
                                    if (result.data.isFront) {
                                        //身份证正面
                                        var name = result.data.Name;
                                        var birthday = result.data.Birthday;
                                        var id = result.data.Id; //证件号码
                                        var address = result.data.Address;
                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
                                        var idCardSmallPic = result.data.smallPic;
                                        var idCardBigPic = result.data.bigPic;
                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
                                        //alert(name+","+Birthday+","+id+","+Address); //扫描获得的数据

                                        //type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                                        $("#name" + flag).val(name); //名称设置

                                        $("#idType" + flag).val('1'); //证件类型设置，扫描身份证，自动切换成身份证
                                        var options = $("#idType" + flag + " option:selected");
                                        $scope["idTypeName" + flag] = options.text();
                                        $("#oldIdType" + flag).val('1');

                                        //设置性别
                                        var is_fandm = id.substring(16, 17);
                                        if (is_fandm % 2 == 1) { //男
                                            $scope.data["radioFlag" + flag] = true;
                                            if (flag == "LF") {
                                                sexLF = 'M';
                                            } else if (flag == "OW") {
                                                sexOW = 'M';
                                            }
                                        } else if (is_fandm % 2 == 0) { //女
                                            $scope.data["radioFlag" + flag] = false;
                                            if (flag == "LF") {
                                                sexLF = 'F';
                                            } else if (flag == "OW") {
                                                sexOW = 'F';
                                            }
                                        }

                                        $("#nativePlaceSelect" + flag).val("CHN"); //国籍设置，设置中国
                                        var options2 = $("#nativePlaceSelect" + flag + " option:selected");
                                        $scope["nativePlaceName" + flag] = options2.text();
                                        $("#nativePlace" + flag).val(options2.val());

                                        $scope["idNo" + flag] = id; //证件号码设置
                                        $("#idNo" + flag).val(id);

                                        //在这里想办法让证件号码聚焦再失焦，这样会填充其他信息
                                        $("#idNo" + flag).focus();

                                        $scope["birthDay" + flag] = birthday; //出生日期设置
                                        $("#birthDay" + flag).val(birthday);

                                        $("#name" + flag).focus(); //焦点重新定位即可

                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
                                        ///***************saveIdCardCache begin******************
                                        //itemId,chdrnum,role,type,keyId,baseVal
                                        //(type,flag) {//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)

                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                        //										var idCardParam={
                                        //												"itemId":"10",
                                        //												"chdrnum":chdrnum01,
                                        //												"role":flag,
                                        //												"type":"0",
                                        //												"idCardSmallPic":idCardSmallPic,
                                        //												"idCardBigPic":idCardBigPic
                                        //										};
                                        if (flag == "LF") {
                                            $scope.flagLF = flag;
                                            $scope.idCardSmallPicLF0 = idCardSmallPic;
                                            $scope.idCardBigPicLF0 = idCardBigPic;
                                            $scope.scanCardIdLF = id;
                                        } else if (flag == "OW") {
                                            $scope.flagOW = flag;
                                            $scope.idCardSmallPicOW0 = idCardSmallPic;
                                            $scope.idCardBigPicOW0 = idCardBigPic;
                                            $scope.scanCardIdOW = id;
                                        }

                                        //										$scope.saveIdCardCache(idCardParam);
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end

                                        //***************saveIdCardCache end******************
                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
                                    } else {
                                        //身份证反面
                                        var validity = result.data.Validity; //有效期
										//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
										var oldValidity=result.data.OldValidity;//有效期
										//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end 
                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
                                        var idCardSmallPic = result.data.smallPic;
                                        var idCardBigPic = result.data.bigPic;
                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end

                                        //存在有效期为长期的情况：
                                        if (validity == '长期' || validity == '终身') {
                                            //加载有限期类型
                                            $scope["availDataType" + flag] = "1"; //身份证默认有限年期
                                            $("#availDataType" + flag).val("1");
											//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
											$("#availDataStart"+flag).val(oldValidity);
											//$("#availDataStart"+type).attr("disabled",true);
											$("#availDataClose"+flag).val("");
											$("#availDataClose"+type).attr("disabled",true);
										}else{
											//加载有限期类型
											$scope["availDataType"+flag] = "2";//身份证默认有限年期
											$("#availDataType"+flag).val("2");
											$("#availDataStart"+type).attr("disabled",false);
											$("#availDataClose"+type).attr("disabled",false);
											$("#availDataStart"+flag).val(oldValidity); //加载有效起始日
											//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                                            $("#availDataClose" + flag).val(validity); //加载有效截止日
                                        }

                                        var options_avail = $("#availDataType" + flag + " option:selected");
                                        $("#availDataTypeMsg" + flag).val(options_avail.text());
                                        $scope["availDataTypeName" + flag] = options_avail.text();

                                        $scope.onIdDateTypeChange(flag); //证件改变操作一次

                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
                                        ///***************saveIdCardCache begin******************
                                        //itemId,chdrnum,role,type,keyId,baseVal
                                        //(type,flag) {//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                        //										var idCardParam={
                                        //												"itemId":"10",
                                        //												"chdrnum":chdrnum01,
                                        //												"role":flag,
                                        //												"type":"1",
                                        //												"idCardSmallPic":idCardSmallPic,
                                        //												"idCardBigPic":idCardBigPic
                                        //										};

                                        if (flag == "LF") {
                                            $scope.flagLF = flag;
                                            $scope.idCardSmallPicLF1 = idCardSmallPic;
                                            $scope.idCardBigPicLF1 = idCardBigPic;
                                            $scope.scanCardDateLF = validity;
                                        } else if (flag == "OW") {
                                            $scope.flagOW = flag;
                                            $scope.idCardSmallPicOW1 = idCardSmallPic;
                                            $scope.idCardBigPicOW1 = idCardBigPic;
                                            $scope.scanCardDateOW = validity;
                                        }
                                        //										$scope.saveIdCardCache(idCardParam);
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                        //***************saveIdCardCache end******************
                                        //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
                                    }
                                    //*********************************待开发逻辑代码区域end**********************************
                                }
                            } else {
                                $scope.smallPic = result.data.smallPic;
                                $scope.bigPic = result.data.bigPic;
                                result.data.smallPic = "";
                                result.data.bigPic = "";
                                cordova.sino.confirmIDCardInfo(function(result) {
                                    if (result.success) {
                                        if (result.data.ok) {
                                            //*********************************待开发逻辑代码区域begin**********************************
                                            if (result.data.isFront) {
                                                //身份证正面
                                                var name = result.data.Name;
                                                var birthday = result.data.Birthday;
                                                var id = result.data.Id; //证件号码
                                                var address = result.data.Address;
                                                //alert(name+","+Birthday+","+id+","+Address); //扫描获得的数据
                                                //alert(name);
                                                //alert($scope.smallPic);

                                                //type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                                                $("#name" + flag).val(name); //名称设置

                                                $("#idType" + flag).val('1'); //证件类型设置，扫描身份证，自动切换成身份证
                                                var options = $("#idType" + flag + " option:selected");
                                                $scope["idTypeName" + flag] = options.text();
                                                $("#oldIdType" + flag).val('1');

                                                //设置性别
                                                var is_fandm = id.substring(16, 17);
                                                if (is_fandm % 2 == 1) { //男
                                                    $scope.data["radioFlag" + flag] = true;
                                                    if (flag == "LF") {
                                                        sexLF = 'M';
                                                    } else if (flag == "OW") {
                                                        sexOW = 'M';
                                                    }
                                                } else if (is_fandm % 2 == 0) { //女
                                                    $scope.data["radioFlag" + flag] = false;
                                                    if (flag == "LF") {
                                                        sexLF = 'F';
                                                    } else if (flag == "OW") {
                                                        sexOW = 'F';
                                                    }
                                                }

                                                $("#nativePlaceSelect" + flag).val("CHN"); //国籍设置，设置中国
                                                var options2 = $("#nativePlaceSelect" + flag + " option:selected");
                                                $scope["nativePlaceName" + flag] = options2.text();
                                                $("#nativePlace" + flag).val(options2.val());

                                                $scope["idNo" + flag] = id; //证件号码设置
                                                $("#idNo" + flag).val(id);

                                                //在这里想办法让证件号码聚焦再失焦，这样会填充其他信息
                                                $("#idNo" + flag).focus();

                                                $scope["birthDay" + flag] = birthday; //出生日期设置
                                                $("#birthDay" + flag).val(birthday);

                                                $("#name" + flag).focus(); //焦点重新定位即可

                                                //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
                                                ///***************saveIdCardCache begin******************
                                                //itemId,chdrnum,role,type,keyId,baseVal
                                                //(type,flag) {//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                                //												var idCardParam={
                                                //														"itemId":"10",
                                                //														"chdrnum":chdrnum01,
                                                //														"role":flag,
                                                //														"type":"0",
                                                //														"idCardSmallPic":$scope.smallPic,
                                                //														"idCardBigPic":$scope.bigPic
                                                //												};


                                                if (flag == "LF") {
                                                    $scope.flagLF = flag;
                                                    $scope.idCardSmallPicLF0 = $scope.smallPic;
                                                    $scope.idCardBigPicLF0 = $scope.bigPic;
                                                    $scope.scanCardIdLF = id;
                                                } else if (flag == "OW") {
                                                    $scope.flagOW = flag;
                                                    $scope.idCardSmallPicOW0 = $scope.smallPic;
                                                    $scope.idCardBigPicOW0 = $scope.bigPic;
                                                    $scope.scanCardIdOW = id;
                                                }

                                                //$scope.saveIdCardCache(idCardParam);
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                                $scope.smallPic = "";
                                                $scope.bigPic = "";
                                                //***************saveIdCardCache end******************
                                                //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
                                            } else {
                                                //身份证反面
                                                var validity = result.data.Validity; //有效期
											     //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
												var oldValidity=result.data.OldValidity;//有效期起始日
											     //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                                                //存在有效期为长期的情况：
                                                if (validity == '长期' || validity == '终身') {
                                                    //加载有限期类型
                                                    $scope["availDataType" + flag] = "1"; //身份证默认有限年期
                                                    $("#availDataType" + flag).val("1");
													//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
													$("#availDataStart"+flag).val(oldValidity);
													//$("#availDataStart"+type).attr("disabled",true);
													$("#availDataClose"+flag).val("");
													$("#availDataClose"+type).attr("disabled",true);
												}else{
													//加载有限期类型
													$scope["availDataType"+flag] = "2";//身份证默认有限年期
													$("#availDataType"+flag).val("2");
													$("#availDataStart"+type).attr("disabled",false);
													$("#availDataClose"+type).attr("disabled",false);
													$("#availDataStart"+flag).val(oldValidity); //加载有效起始日
													//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
                                                    $("#availDataClose" + flag).val(validity); //加载有效截止日
                                                }

                                                var options_avail = $("#availDataType" + flag + " option:selected");
                                                $("#availDataTypeMsg" + flag).val(options_avail.text());
                                                $scope["availDataTypeName" + flag] = options_avail.text();

                                                $scope.onIdDateTypeChange(flag); //证件改变操作一次

                                                //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
                                                ///***************saveIdCardCache begin******************
                                                //itemId,chdrnum,role,type,keyId,baseVal
                                                //(type,flag) {//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                                //												var idCardParam={
                                                //														"itemId":"10",
                                                //														"chdrnum":chdrnum01,
                                                //														"role":flag,
                                                //														"type":"1",
                                                //														"idCardSmallPic":$scope.smallPic,
                                                //														"idCardBigPic":$scope.bigPic
                                                //												};


                                                if (flag == "LF") {
                                                    $scope.flagLF = flag;
                                                    $scope.idCardSmallPicLF1 = $scope.smallPic;
                                                    $scope.idCardBigPicLF1 = $scope.bigPic;
                                                    $scope.scanCardDateLF = validity;
                                                } else if (flag == "OW") {
                                                    $scope.flagOW = flag;
                                                    $scope.idCardSmallPicOW1 = $scope.smallPic;
                                                    $scope.idCardBigPicOW1 = $scope.bigPic;
                                                    $scope.scanCardDateOW = validity;
                                                }

                                                //												$scope.saveIdCardCache(idCardParam);
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                                //***************saveIdCardCache end******************
                                                //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
                                            }
                                            ///*********************************待开发逻辑代码区域end**********************************
                                        }
                                    }
                                }, result.data);
                            }
                        }
                    }
                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190414 start
                });
                //S2019012807164 - 信易通OCR识别功能 add by csf 20190414 end
                //PC端开发测试用
                /*var testVal="R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
                var result = {
                	data : {
                		Name:"张三",
                		Birthday:"2015-03-23",
                		Id:"440771201503231715",
                		Address:"广东省广州市天河区某街道23号",
                		//Validity:"2050-08-23",
                		Validity:"长期",
                		smallPic:testVal,
                		bigPic:testVal,
                		ok:"true",
                		isFront:true,//正面
                		//isFront:false,//反面
                	}
                };

                if(result.data.ok){
                	///*********************************待开发逻辑代码区域begin**********************************
                	if(result.data.isFront){
                		//身份证正面
                		var name=result.data.Name;
                		var birthday=result.data.Birthday;
                		var id =result.data.Id;//证件号码
                		var address=result.data.Address;
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
                		var idCardSmallPic=result.data.smallPic;
                		var idCardBigPic=result.data.bigPic;
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
                		//alert(name+","+Birthday+","+id+","+Address); //扫描获得的数据
                		//console.log(idCardBase64Img); //idCardBase64Img
                		
                		//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                		$("#name"+flag).val(name); //名称设置
                		
                		$("#idType"+flag).val('1');     //证件类型设置，扫描身份证，自动切换成身份证
                		var options =$("#idType"+flag+" option:selected");
                		$scope["idTypeName"+flag] = options.text();
                		$("#oldIdType"+flag).val('1');
                		
                	 	//设置性别
                		var is_fandm = id.substring(16,17);
                	 	if(is_fandm%2==1){ //男 
                	 		$scope.data["radioFlag"+flag] = true;
                	 		if(flag == "LF"){
                	 			sexLF = 'M';
                	 		}else if(flag == "OW"){
                	 			sexOW = 'M';
                	 		}
                	 	}else if(is_fandm%2==0){ //女
                	 		$scope.data["radioFlag"+flag] = false;
                	 		if(flag == "LF"){
                	 			sexLF = 'F';
                	 		}else if(flag == "OW"){
                	 			sexOW = 'F';
                	 		}
                	 	}
                		
                		$("#nativePlaceSelect"+flag).val("CHN");//国籍设置，设置中国
                		var options2 =$("#nativePlaceSelect"+flag+" option:selected");
                		$scope["nativePlaceName"+flag] = options2.text();
                		$("#nativePlace"+flag).val(options2.val());
                		
                		$scope["idNo"+flag] = id;   //证件号码设置
                		$("#idNo"+flag).val(id);

                		$("#idNo"+flag).focus();
                		
                		$scope["birthDay"+flag] =  birthday;      //出生日期设置
                		$("#birthDay"+flag).val(birthday);
                		
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
                		///***************saveIdCardCache begin******************
                		//itemId,chdrnum,role,type,keyId,baseVal
                		//(type,flag) {//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                		var idCardParam={
                				"itemId":"10",
                				"chdrnum":chdrnum01,
                				"role":flag,
                				"type":"0",
                				"idCardSmallPic":idCardSmallPic,
                				"idCardBigPic":idCardBigPic
                		};
                		$scope.saveIdCardCache(idCardParam);
                		//***************saveIdCardCache end******************
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
                		
                		$("#name"+flag).focus();//焦点重新定位即可
                	}else{
                		//身份证反面
                		var validity=result.data.Validity;//有效期
                		
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
                		var idCardSmallPic=result.data.smallPic;
                		var idCardBigPic=result.data.bigPic;
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
                		
                		//存在有效期为长期的情况：
                		if(validity=='长期' || validity=='终身'){
                			//加载有限期类型
                			$scope["availDataType"+flag] = "1";//身份证默认有限年期
                			$("#availDataType"+flag).val("1");
                			
                			$("#availDataClose"+type).val("");
                			$("#availDataClose"+type).attr("disabled",true);
                		}else{
                			//加载有限期类型
                			$scope["availDataType"+flag] = "2";//身份证默认有限年期
                			$("#availDataType"+flag).val("2");
                		}
                		var options_avail =$("#availDataType"+flag+" option:selected");
                		$("#availDataTypeMsg"+flag).val(options_avail.text());
                		$scope["availDataTypeName"+flag]=options_avail.text();
                		
                		$("#availDataClose"+flag).val(validity); //加载有效截止日
                		
                		$scope.onIdDateTypeChange(flag);   //证件改变操作一次
                		
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
                		///***************saveIdCardCache begin******************
                		//itemId,chdrnum,role,type,keyId,baseVal
                		//(type,flag) {//type为Bbr或者Tbr(被保人或投保人)、flag为LF(被保人)或者OW(投保人)
                		var idCardParam={
                				"itemId":"10",
                				"chdrnum":chdrnum01,
                				"role":flag,
                				"type":"1",
                				"idCardSmallPic":idCardSmallPic,
                				"idCardBigPic":idCardBigPic
                		};
                		$scope.saveIdCardCache(idCardParam);
                		//***************saveIdCardCache end******************
                		//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
                	}
                	//*********************************待开发逻辑代码区域end**********************************
                }*/


            }

            /**
             * 扫描银行卡信息
             */
            $scope.scanBankCardInfo = function() {
                //移动端
                /*cordova.sino.getBankCardInfo(function(result){
                	if(result.success){
                		if(!result.data.exit){
                			if(result.data.ok){
                				var CardNumber=result.data.CardNumber;
                				var CardInsName=result.data.CardInsName;
                				var BankCardType=result.data.BankCardType;
                				alert(CardNumber+","+CardInsName+","+BankCardType);
                				//逻辑控制code

                			}
                		}
                	}else{
                		//sino.alert("扫描银行卡信息失败:"+result.data.errormsg);
                		myFactory.alert('','扫描银行卡信息失败:'+result.data.errormsg,'info');
                	}
                });*/

                //PC端开发测试用
                var result = {
                    data: {
                        CardNumber: "6216678911114523785",
                        CardInsName: "中国银行",
                        BankCardType: "借记卡",
                        ok: true
                    }
                };
                if (result.data.ok) {

                    /*********************************待开发逻辑代码区域begin**********************************/
                    var CardNumber = result.data.CardNumber;
                    var CardInsName = result.data.CardInsName;
                    var BankCardType = result.data.BankCardType;
                    alert(CardNumber + "," + CardInsName + "," + BankCardType);



                    /*********************************待开发逻辑代码区域end**********************************/

                }

            }

            /**
             * S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711
             * OCR证件扫描证件信息缓存
             */
            $scope.saveIdCardCache = function(idCardParam) {
                var idCardItems = { "idCardItems": idCardParam };
                var token = sessionStorage.getItem("token");
                var timestamp = myFactory.getTimetamp();
                var sfis = "token-timestamp";
                var signStr = "token=" + token + "&timestamp=" + timestamp;
                var sign = myFactory.hex(signStr);
                $http({
                    method: 'POST',
                    url: app.domain + 'img/saveIdCard10Cache.action',
                    data: { paramsMap: idCardItems, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                }).then(function successCallback(response) {
                    if (response.data.success) {
                        console.log("saveIdCardCache ok");
                    }
                }, function errorCallback(response) {
                    console.log("saveIdCardCache error");
                });
            }

            /**
             * 扫描身份证反面信息
             */
            $scope.scanBackIDCardInfoItem10 = function(type, flag) {
                $.confirm("请扫描身份证反面", "", function() {
                    $scope.scanIDCardInfoItem10(type, flag);
                });
            }
    		String.prototype.replaceAll = function(s1, s2) {
    			return this.replace(new RegExp(s1, "gm"), s2);
    		}
        }]);

    //指针弹窗
    app.directive('infoid', function() {
        return {
            restrict: 'EA', //指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
            templateUrl: 'html/input/content_base_info.html' + app.clearCache,
            replace: true, //设置解析后，DOM声明的指令是否消失
            link: function(scope, element, attrs) { //链接函数负责注册DOM事件和更新DOM,
                console.log('指令完成');
            }
        }
    });

})(app)